home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / dosutils / tsbat50.zip / D.BAT < prev    next >
DOS Batch File  |  1992-08-28  |  3KB  |  117 lines

  1. echo off
  2. echo.
  3. echo ┌───────────────────────────────────────────────────┐
  4. echo │ Directory with sort and generalized name matching │
  5. echo │ By Prof. Timo Salmi, ts@uwasa.fi, Fri 28-Aug-1992 │
  6. echo └───────────────────────────────────────────────────┘
  7. echo.
  8.  
  9. rem If no parameters are given to the batch, then display help
  10. if "%1"=="" goto _help
  11.  
  12. rem Check that a (ram)disk exists on r:
  13. if not exist r:\nul goto _err1
  14.  
  15. rem Eliminate wildcards (they are implicit)
  16. for %%f in (%1) do if "%%f"=="%1" goto _makeup
  17. echo Wildcards are implicit and should not be used
  18. goto _out
  19.  
  20. rem Make the searchstring uppercase
  21. :_makeup
  22. set _tmp=%path%
  23. path %1
  24. set _upcase=%path%
  25. path %_tmp%
  26.  
  27. rem Make a temporary directory
  28. dir *.* > r:\d.tmp
  29.  
  30. rem Read the switches
  31. set _n=
  32. set _e=
  33. set _s=
  34. set _r=
  35. :_loop
  36. shift
  37. if "%1"=="" goto _sort_1
  38. if "%1"=="/n" set _n=yes
  39. if "%1"=="/N" set _n=yes
  40. if "%1"=="/e" set _e=yes
  41. if "%1"=="/E" set _e=yes
  42. if "%1"=="/s" set _s=yes
  43. if "%1"=="/S" set _s=yes
  44. if "%1"=="/r" set _r=/r
  45. if "%1"=="/R" set _r=/r
  46. goto _loop
  47.  
  48. rem The sorting routines
  49. :_sort_1
  50. if "%_n%"=="yes" goto _sort_n
  51. :_sort_2
  52. if "%_e%"=="yes" goto _sort_e
  53. :_sort_3
  54. if "%_s%"=="yes" goto _sort_s
  55. :_sort_4
  56. goto _display
  57.  
  58. :_sort_n
  59. sort %_r% < r:\d.tmp > r:\tmp$$$.$$$
  60. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  61. del r:\tmp$$$.$$$
  62. goto _sort_2
  63.  
  64. :_sort_e
  65. sort %_r% /+10 < r:\d.tmp > r:\tmp$$$.$$$
  66. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  67. del r:\tmp$$$.$$$
  68. goto _sort_3
  69.  
  70. :_sort_s
  71. sort %_r% /+14 < r:\d.tmp > r:\tmp$$$.$$$
  72. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  73. del r:\tmp$$$.$$$
  74. goto _sort_4
  75.  
  76. rem Find the entries containing the searchstring
  77. :_display
  78. find "%_upcase%" r:\d.tmp | more
  79. goto _out
  80.  
  81. :_help
  82. echo D is a DIR command enhancement. It uses a generalized searchstring which is
  83. echo matched with the file name REGARDLESS of the location of the string within
  84. echo the file name. Wildcards (* and ?) should not be used. They are implicit.
  85. echo.
  86. echo Usage: D SearchString [/n] [/e] [/s] [/r]
  87. echo                         │    │    │    └─ Reverse the sort
  88. echo                         │    │    └─ Sort by size
  89. echo                         │    └─ Sort by extension
  90. echo                         └─ Sort by name
  91. echo.
  92. echo Examples: D bat /s /r  (all batch files sorted from biggest to smallest)
  93. echo           D - /n       (see the entire sorted directory (- or . or :) )
  94. echo           D j          (all file names having a J in them, unsorted)
  95. echo           D /r         (error in logic, no sort key has been defined)
  96. echo.
  97. echo If you get an "Out of environment space" message, increase your environment
  98. echo space by using shell configuration in config.sys apply the following MsDos
  99. echo 3.30 example: shell=c:\bin\command.com /e:1024 /p
  100. goto _out
  101.  
  102. :_err1
  103. echo D.BAT assumes by default a (ram)disk in drive R. If you do not have
  104. echo that drive is available, then you should substitute r:\d.bat throughout
  105. echo the batch as relevant for your own configuration. (Using a ramdisk is
  106. echo advisable, because potential read-only problems are avoided.)
  107.  
  108. :_out
  109. if exist r:\d.tmp del r:\d.tmp
  110. set _tmp=
  111. set _upcase=
  112. set _n=
  113. set _e=
  114. set _s=
  115. set _r=
  116. echo on
  117.